package org.iku.common;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.iku.dao.ItemIndexDAO;
import org.iku.entity.Actress;
import org.iku.entity.Category;

public class ActressTool {
	
	
	private static Map<Integer,Actress> actressMap;
	private static Map<String,Integer> invertedMap;
	
	public static void init(ItemIndexDAO itemIndexDAO){
		
		List<Actress> actresses = itemIndexDAO.getAllActresses();
		
		if(null == actressMap || actressMap.size()<=0){
			actressMap = new HashMap<Integer, Actress>();
		}
		
		if(null == invertedMap || invertedMap.size()<=0){
			invertedMap = new HashMap<String, Integer>();
		}
		
		for(Actress actress : actresses){
			actressMap.put(actress.getId(), actress);
			invertedMap.put(actress.getNameCn(), actress.getId());
			invertedMap.put(actress.getNameEn(), actress.getId());
		}
	}
	
	public static Actress getActress(int id){
		return actressMap.get(id);
	}
	
	public static boolean containActress(String name){
		return invertedMap.containsKey(name);
	}
	
	public static Actress getActress(String name){
		Integer id = invertedMap.get(name);
		return actressMap.get(id);
}
	
	public static void addActress(Actress actress){
		actressMap.put(actress.getId(), actress);
		invertedMap.put(actress.getNameCn(), actress.getId());
		invertedMap.put(actress.getNameEn(), actress.getId());
	}
	
}
